from rest_framework.authentication import BaseAuthentication
from app01.models import UserToken
from rest_framework import exceptions


class Authentions(BaseAuthentication):

    def authenticate(self, request):
        token = request.query_params.get('token')

        user_token = UserToken.objects.filter(token=token).first()

        if user_token:
            # request.user
            # request.auth
            return user_token.user, user_token
        else:
            raise exceptions.AuthenticationFailed('请登录')

    def authenticate_header(self, request):
        pass
